package com.coffee.soft.service.impl;

import com.coffee.soft.entity.Items;
import com.coffee.soft.entity.ItemsShow;
import com.coffee.soft.mapper.ItemsMapper;
import com.coffee.soft.service.ItemsEatDrinkDiyFirst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Author:LiuRuidong
 * @Description: 第一次触发吃点啥喝点啥DIY时候的操作
 * @Date: Created in 1:36 2018/2/5
 * @Modified By:
 */
@Service
public class ItemsEatDrinkDiyFirstImpl implements ItemsEatDrinkDiyFirst{

    @Autowired
    private ItemsMapper itemsMapper;
    /**
     * @Author：LiuRuidong
     * @Description: 查询前4个吃的东西
     * @Date:2018/2/5 1:41
     * @Param:
     * @return
     */
    @Override
    public List<ItemsShow> eatItems() {
        int i = 0 ;
//       存储要展示的东西
        List<ItemsShow> itemsShowList = new ArrayList();
//查询出来的所有吃的
        List<Items> itemsList = itemsMapper.selectEat();
//迭代吃的
        Iterator<Items> iterator = itemsList.iterator();
        ItemsShow itemsShow = null;
        while(iterator.hasNext()){
            Items items = iterator.next();
                for(;i<4;i++) {
                    itemsShow = new ItemsShow();
                    itemsShow.setItemsId(items.getItemsId());
                    itemsShow.setItemsName(items.getItemsName());
                    itemsShow.setItemsDiscountPrice(items.getItemsPrice()*items.getItemsDiscount());
                    itemsShow.setItemsPicture(items.getItemsPicture());
                    itemsShowList.add(itemsShow);
                    if(iterator.hasNext()){
                        items = iterator.next();
                    }else{
                        iterator = itemsList.iterator();
                    }
                }
                if (i==4){
                    break;
                }

        }

        return itemsShowList;
    }
    /**
     * @Author：LiuRuidong
     * @Description: 查询前4个喝的东西
     * @Date:2018/2/5 1:41
     * @Param:
     * @return
     */
    @Override
    public List<ItemsShow> drinkItems() {
        int i=0;
//        存储要展示的东西
        List<ItemsShow> itemsShowList = new ArrayList();
//查询出来的所有喝的
        List<Items> itemsList = itemsMapper.selectDrink();
//迭代喝的
        Iterator<Items> iterator = itemsList.iterator();
        ItemsShow itemsShow = null;
        while(iterator.hasNext()){
            Items items = iterator.next();
            for(;i<4;i++) {
                itemsShow = new ItemsShow();
                itemsShow.setItemsId(items.getItemsId());
                itemsShow.setItemsName(items.getItemsName());
                itemsShow.setItemsDiscountPrice(items.getItemsPrice()*items.getItemsDiscount());
                itemsShow.setItemsPicture(items.getItemsPicture());
                itemsShowList.add(itemsShow);
                if(iterator.hasNext()){
                    items = iterator.next();
                }else{
                    iterator = itemsList.iterator();
                }
            }
            if (i==4){
                break;
            }
        }

        return itemsShowList;
    }
    /**
     * @Author：LiuRuidong
     * @Description: 查询前4个DIY的东西
     * @Date:2018/2/5 1:41
     * @Param:
     * @return
     */
    @Override
    public List<ItemsShow> diyItems() {
        int i=0;
//        存储要展示的东西
        List<ItemsShow> itemsShowList = new ArrayList();
//查询出来的DiY
        List<Items> itemsList = itemsMapper.selectAll();
//迭代DIY的
        Iterator<Items> iterator = itemsList.iterator();
        ItemsShow itemsShow = null;
        while(iterator.hasNext()){
            Items items = iterator.next();
            for(;i<4;i++) {
                itemsShow = new ItemsShow();
                itemsShow.setItemsId(items.getItemsId());
                itemsShow.setItemsName(items.getItemsName());
                itemsShow.setItemsDiscountPrice(items.getItemsPrice()*items.getItemsDiscount());
                itemsShow.setItemsPicture(items.getItemsPicture());
                itemsShowList.add(itemsShow);
                if(iterator.hasNext()){
                    items = iterator.next();
                }else{
                    iterator = itemsList.iterator();
                }
            }
            if(i==4){
                break;
            }
        }
        return itemsShowList;
    }
}
